var moduleNo;
var subShop;
$(function () {
    moduleNo = getQueryString("moduleNo");
    subShop = getQueryString("subShop");
    vm.moduleError.moduleCode = moduleNo;
    vm.moduleError.delFlag = 1;
    vm.moduleError.errorDisStatus = 0;
    vm.moduleError.isReplaceSparepart = 1;
    vm.moduleError.isOff = 1;
    vm.moduleError.workshop = subShop;
    vm.getTypeTree();
})
var setting = {
    data: {
        simpleData: {
            enable: true,
            idKey: "id",
            pIdKey: "superType",
            rootPId: 0
        },
        key: {
            url: "nourl",
            name: "typeName" //name 与 typeName 绑定
        },
    },
    callback: {
        onClick: function () {
            var node = typeTree.getSelectedNodes();
            vm.q.id = node[0].id;
            // vm.query()
        }
    }
};
var vm = new Vue({
    el: '#rrapp',
    data: {
        showList: true,
        title: null,
        moduleError: {
            updateTime: '',
            updateUser: '',
            createTime: '',
            createUser: '',
            delFlag: '',
            errorCheckTime: '',
            errorDisStatus: '',
            errorReviewUser: '',
            maintainRecord: '',
            productType: '',
            productSeries: '',
            moduleType: '',
            dealOpinion: '',
            dealSuggest: '',
            description: '',
            productLine: '',
            workshop: '',
            maintainTime: '',
            isReplaceSparepart: '',
            isOff: '',
            moduleCode: '',
            id: '',
        },
        ruleValidate: {
            // moduleCode: [
            //     {required: true, message: '模具编码不能为空', trigger: 'blur'}
            // ]
        },
        q: {
            moduleCode: ''
        }
    },
    methods: {
        add: function () {
            vm.showList = false;
            vm.title = "新增";
            vm.moduleError = {
                updateTime: '',
                updateUser: '',
                createTime: '',
                createUser: '',
                delFlag: 1,
                errorCheckTime: '',
                errorDisStatus: 0,
                errorReviewUser: '',
                maintainRecord: '',
                productType: '',
                productSeries: '',
                moduleType: '',
                dealOpinion: '',
                dealSuggest: '',
                description: '',
                productLine: '',
                workshop: '',
                maintainTime: new Date(),
                isReplaceSparepart: 1,
                isOff: 1,
                moduleCode: moduleNo,
                id: '',
            };
        },
        save: function (event) {
            var url = "../moduleerror/save";
            Ajax.request({
                url: url,
                params: JSON.stringify(vm.moduleError),
                type: "POST",
                contentType: "application/json",
                successCallback: function (r) {
                    alert('操作成功', function (index) {
                        vm.reload();
                    });
                }
            });
        },
        getProdect: function () {
            //获取模具系列
            openWindow({
                type: 2,
                title: '<i class="fa fa-bars"></i> 模具系列',
                btn: ["提交", "关闭"],
                content: '../module/moduleSeriesSelect.html',
                btn1: function (index) {
                    var iframeWin = window["layui-layer-iframe" + index];
                    var res = iframeWin.getDates();
                    if (!res) {
                        iview.Message.error("请选择一条记录");
                    } else {
                        //
                        vm.moduleError.productSeries = res.modelCode;
                        vm.moduleError.productType = res.modelName;
                    }
                    layer.close(index);
                }
            })
        },
        typeTree: function () {
            openWindow({
                title: "选择模具类型",
                area: ['300px', '450px'],
                content: jQuery("#TypeLayer"),
                btn: ['确定', '取消'],
                btn1: function (index) {
                    var node = typeTree.getSelectedNodes();
                    //选择上级部门
                    // vm.faultType.typePid = node[0].id;
                    // console.log(node[0].id);
                    vm.moduleError.moduleType = node[0].typeName;
                    // console.log(node[0].typeName);
                    layer.close(index);
                }
            });
        },
        getTypeTree: function () {
            //加载故障类型树
            Ajax.request({
                url: "../moduletype/select",
                async: true,
                successCallback: function (r) {
                    var tree = r.typeList;
                    typeTree = $.fn.zTree.init($("#TypeTree"), setting, tree);
                }
            });
        },
        reload: function (event) {
            layer.closeAll();
        }
    }
})


var getFormDates = function () {
    return vm.moduleError;
}